<template>
  <view class="content1">
    <!-- <view class="chhose_item" v-if="isShow">
      <u-tabs
        :list="list"
        lineWidth="0"
        lineColor="#f56c6c"
        :activeStyle="{
          color: '#55B877',
          height: '56rpx',
          'line-height': '56rpx',
          'text-align': 'center',
          'border-radius': '32rpx 32rpx 32rpx 32rpx',
          'font-size': '28rpx',
        }"
        :inactiveStyle="{
          height: '56rpx',
          'line-height': '56rpx',
          'text-align': 'center',
          color: '#ADADAD',
          'font-size': '28rpx',
        }"
        itemStyle="padding:0 30rpx; height: 56rpx'width: 100rpx"
        @change="change"
      >
      </u-tabs>
    </view> -->
    <view
      class="card"
      v-for="(item, index) in listv"
      :key="index"
      :class="blackColor ? 'card1' : ''"
      @click="goPage(item)"
    >
      <view class="all_detail" >
        <view class="card_top">
          <view class="card_name" :class="blackColor ? 'card_name1' : ''">{{
            item.title
          }}</view>
          <view class="card_icon" v-show="flag"
            ><u-icon name="arrow-right" color="#ADADAD" size="20"></u-icon
          ></view>
          <view
            v-show="!flag"
            class="item_left_clickView"
            @click.stop="changeClickItem(item)"
          >
            <image
              v-if="!item.clickable"
              class="item_left_click"
              src="../../static/images/my/icon_grzy_quanxuan.png"
              mode=""
            ></image>
            <image
              v-else
              class="item_left_clickable"
              src="../../static/images/my/icon_grzy_xc_xuanzhong.png"
              mode=""
            ></image>
          </view>
        </view>
        <view class="card_content_box">
          <view class="card_content" :class="blackColor ? 'card_content1' : ''" v-html="item.content">
            <!-- {{item.content}} -->
          </view>
          <view
            class="card_content_box_preview"
            v-if="my_level_id < item.grade_auth"
            @click.stop="goMember"
          >
            该内容仅支持{{
              item.grade_auth == 1
                ? "元气驿站"
                : item.grade_auth == 2
                ? "启初梦谷"
                : item.grade_auth == 3
                ? "青空天台"
                : item.grade_auth == 4
                ? "无极云顶"
                : item.grade_auth == 5
                ? "返朴归源"
                : ""
            }}及以上行者查看
          </view>
        </view>
        
      </view>

      <!-- 预览样式 -->
      <!-- <view class="Preview_style" v-else @click.stop="goMember">
        该内容仅支持{{
          item.grade_auth == 1
            ? "元气驿站"
            : item.grade_auth == 2
            ? "启初梦谷"
            : item.grade_auth == 3
            ? "青空天台"
            : item.grade_auth == 4
            ? "无极云顶"
            : item.grade_auth == 5
            ? "返朴归源"
            : ""
        }}及以上行者查看
      </view> -->

      <view class="card_bottom">
        <!-- 头像 -->
        <view class="avatar" v-if="showName">
          <image
            class="zanImg"
            :src="item.user.avatar_url"
            @click.stop="goHome(item.user.user_id)"
          ></image>
          <view class="nick" :class="blackColor ? 'nick1' : ''">{{
            item.user.nick_name
          }}</view>
        </view>
        <view class="avatarRight">
          <view class="time">{{ item.create_time }}</view>
        </view>
        <!-- <view class="avatar_show">仅自己可见</view> -->
        <!-- <view class="avatar_show">粉丝可见</view> -->
        <!-- <view class="avatar_show">公开</view> -->
      </view>
      <!-- <view
        class="inp"
        :class="blackColor ? 'inp1' : ''"
        v-if="isInp"
        @click.stop=""
      >
        <u--input
          placeholder="我也来写一写"
          border="none"
          placeholderStyle="font-size:30rpx;color:#888888;"
          prefixIconStyle="font-size: 42rpx;color: #888888"
          color="#888888"
          v-model="item.value"
          @change="change1"
          inputAlign="left"
          @confirm="confirm"
        ></u--input>
      </view> -->
    </view>
    <view></view>

    <u-modal
      :show="show"
      :title="'提示'"
      :content="'您还不是行者身份，无法参与共创若想要参与共创需要开通行者身份！'"
      :showCancelButton="true"
      confirmText="去开通"
      cancelText="取消"
      confirmColor="#55B877"
      @confirm="submit"
      @cancel="show = false"
    ></u-modal>

    <view class="bottom" v-show="!flag">
      <view class="bottom_left">
        <view @click="changeClick">
          <image
            v-if="!clickableAll"
            class="item_left_click"
            src="../../static/images/my/icon_grzy_quanxuan.png"
            mode=""
          ></image>
          <image
            v-else
            class="item_left_click"
            src="../../static/images/my/icon_grzy_xc_xuanzhong.png"
            mode=""
          ></image>
        </view>
        <view class="bottom_left_text">全选</view>
      </view>
      <view class="bottom_right" @click="deleteFn">删除</view>
    </view>

    <u-modal
      :show="show1"
      :title="title"
      :content="content"
      confirmColor="#55B877"
      :closeOnClickOverlay="true"
      @confirm="confirm1"
      @close="close"
      @cancel="cancel"
      :showCancelButton="true"
    ></u-modal>

    <view class="empty_view" v-if="listv && listv.length == 0">
      <image
        class="item_left_clickable"
        src="../../static/images/my/kong.png"
        mode=""
      ></image>
      <view>暂时还没有相关信息~</view>
    </view>
  </view>
</template>
    <script>
export default {
  props: {
    showTab: {
      type: Boolean,
      default: true,
    },
    isShow: {
      type: Boolean,
      default: true,
    },
    showName: {
      type: Boolean,
      default: true,
    },
    isInp: {
      type: Boolean,
      default: true,
    },
    flag: {
      type: Boolean,
      default: true,
    },
    blackColor: {
      type: Boolean,
      default: false,
    },
    list: {
      type: Array,
      default: () => {
        return [];
      },
    },
    my_level_id: {
      type: Number,
      default: 0,
    },
  },
  watch: {
    list: {
      deep: true, // 深度监听每一个属性值, 如果是对象可以深度监听
      immediate: true, // 进入页面后立即自动调用handler函数
      handler(newValue) {
        this.listv = newValue;
        if (this.listv) {
          for (let i = 0; i < this.listv.length; i++) {
            this.listv[i].clickable = false;
          }
        }

        console.log(this.listv, "newList");
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
      list1: [
        {
          name: "按浏览",
        },
        {
          name: "按点赞",
        },
        {
          name: "最新",
        },
      ],
      listValue: [
        {
          title: "石壁与野花",
          text: "它与生俱来的底色当然不是黑暗诞下的。是旷野里的锈迹，......",
          headImg: "https://cdn.uviewui.com/uview/album/1.jpg",
          name: "柳语晨",
          time: "2023年09月06日",
          clickable: false,
          value: "",
        },
        {
          title: "石壁与野花",
          text: "它与生俱来的底色当然不是黑暗诞下的。是旷野里的锈迹，......",
          headImg: "https://cdn.uviewui.com/uview/album/1.jpg",
          name: "柳语晨",
          time: "2023年09月06日",
          clickable: false,
          value: "",
        },
        {
          title: "石壁与野花",
          text: "它与生俱来的底色当然不是黑暗诞下的。是旷野里的锈迹，......",
          headImg: "https://cdn.uviewui.com/uview/album/1.jpg",
          name: "柳语晨",
          time: "2023年09月06日",
          clickable: false,
          value: "",
        },
      ],
      clickableAll: false,
      value: "",
      show: false,
      show1: false,
      title: "确认删除",
      content: "确认删除选中内容？",
      listv: [],
    };
  },
  methods: {
    change(e) {
      console.log("eeeeeee", e);
      this.currentIndex = e.index;
    },
    goPage(item) {
      if (this.isInp) {
        uni.navigateTo({
          url: `/pages/detail/coCreateFly?id=${item.id}`,
        });
      } else {
        console.log("itemmmm", item);
        uni.navigateTo({
          url: `/pages/detail/flyDetail?detailType=shi&from=search&currentId=${item.id}`,
        });
      }
    },
    change1() {},
    confirm() {
      console.log("eeeeee");
      if (this.isInp) {
        this.show = true;
      }
    },
    submit() {
      uni.navigateTo({
        url: "/pages/member/index",
      });
    },
    changeClickItem(item) {
      this.$forceUpdate();
      item.clickable = !item.clickable;
      // 判断是否全选
      let all = true;
      for (let i = 0; i < this.listv.length; i++) {
        if (this.listv[i].clickable == false) {
          all = false;
        }
      }
      if (all) {
        this.clickableAll = true;
      } else {
        this.clickableAll = false;
      }
    },
    changeClick() {
      this.clickableAll = !this.clickableAll;
      if (this.clickableAll) {
        for (let i = 0; i < this.listv.length; i++) {
          this.listv[i].clickable = true;
        }
      } else {
        for (let i = 0; i < this.list.length; i++) {
          this.listv[i].clickable = false;
        }
      }
    },
    confirm1() {
      let arr = [];
      let num = 0;
      for (let i = 0; i < this.listv.length; i++) {
        if (this.listv[i].clickable == true) {
          arr.push(this.listv[i].history_id);
          num++;
        }
      }
      console.log(arr, "数组");
      this.deletFn(arr);
    },
    close() {
      this.show1 = false;
    },
    cancel() {
      this.show1 = false;
    },
    // 删除按钮
    deleteFn() {
      let isTrue = true;
      for (let i = 0; i < this.listv.length; i++) {
        console.log(this.listv[i].clickable);
        if (this.listv[i].clickable == true) {
          isTrue = false;
        }
      }
      if (isTrue == true) {
        uni.$u.toast("您还未选择内容");
      } else {
        this.show1 = true;
      }
    },
    // 删除接口
    deletFn(arr) {
      // 共创删除
      this.$http
        .historyDel_his_gongchuang({ ids: arr })
        .then((res) => {
          uni.$u.toast(res.message);
          this.show1 = false;
          setTimeout(() => {
            this.$emit("updateDataGongShi");
          }, 1000);
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    // 去个人主页
    goHome(user_id) {
      uni.navigateTo({
        url: `/pages/home/home?user_id=${user_id}`,
      });
    },
    // 跳会员页面
    goMember() {
      uni.navigateTo({
        url: `/pages/member/index`,
      });
    },
  },
};
</script>
    <style scoped lang="scss">
.content1 {
  height: 100%;
  box-sizing: border-box;
  .card {
    // margin-left: 30rpx;
    margin-top: 32rpx;
    width: 690rpx;
    // height: 338rpx;
    // background: rgba(39, 39, 39, 0.5);
    background: #f7f8fa;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    // padding-bottom: 32rpx;
    box-sizing: border-box;
    .all_detail {
    }
    .Preview_style {
      width: 100%;
      height: 216rpx;
      border-radius: 16rpx;
      // background: rgba(105, 113, 151, 0.7);
      margin-top: 24rpx;
      text-align: center;
      line-height: 216rpx;
      // color: white;
    }
    .card_top {
      display: flex;
      justify-content: space-between;
      padding: 32rpx 32rpx 24rpx;
      .card_name {
        font-size: 32rpx;
        font-weight: 400;
        color: #444444;
      }
      .card_name1 {
        color: #eee;
      }
      .item_left_clickView {
        // margin-right: 24rpx;
        .item_left_click {
          width: 40rpx;
          height: 40rpx;
        }
        .item_left_clickable {
          width: 40rpx;
          height: 40rpx;
        }
      }
    }
    .card_content_box {
      position: relative;
      .card_content_box_preview {
        color: #eeeeee;
        padding-top: 30rpx;
        box-sizing: border-box;
        position: absolute;
        top: 0;
        background: linear-gradient(
          360deg,
          rgba(48, 53, 77, 1) 50%,
          rgba(49, 57, 79, 0) 100%
        );
        text-align: center;
        width: 100%;
        height: 100%;
      }
    }
    .card_content {
      padding-left: 32rpx;
      width: 269rpx;
      height: 114rpx;
      font-size: 26rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #444444;
      line-height: 38rpx;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      overflow: hidden;
      -webkit-line-clamp: 3;
      text-overflow: ellipsis;
    }
    .card_content1 {
      color: #eee;
    }
    .card_bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 32rpx;
      .avatar {
        display: flex;
        align-items: center;
        .zanImg {
          width: 56rpx;
          height: 56rpx;
          border-radius: 28rpx;
        }
        .nick {
          font-size: 24rpx;
          margin-left: 16rpx;
          font-weight: 400;
          color: #444444;
        }
        .nick1 {
          color: #eee;
        }
      }
      .avatarRight {
        font-size: 24rpx;
        font-weight: 400;
        color: #adadad;
      }
      .avatar_show {
        font-size: 24rpx;
        font-weight: 400;
        color: #adadad;
      }
    }
  }
  .card1 {
    background: rgba(39, 39, 39, 0.5);
  }
}
.inp {
  width: 626rpx;
  margin-left: 32rpx;
  height: 88rpx;
  background: #eeeeee;
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  display: flex;
  align-items: center;
  padding: 22rpx 32rpx;
  box-sizing: border-box;
}
.inp1 {
  background: rgba(39, 44, 41, 0.5);
}
.bottom {
  width: 100%;
  height: 112rpx;
  background: #272727;
  position: fixed;
  bottom: 0;
  left: 0;
  padding: 16rpx 30rpx;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .bottom_left {
    display: flex;
    align-items: center;
    .item_left_click {
      width: 40rpx;
      height: 40rpx;
    }
    .bottom_left_text {
      margin-left: 16rpx;
      color: #eeeeee;
      font-size: 30rpx;
    }
  }

  .bottom_right {
    width: 250rpx;
    height: 80rpx;
    background: #ee6060;
    border-radius: 48rpx;
    text-align: center;
    line-height: 80rpx;
    font-size: 30rpx;
    color: #eeeeee;
  }
}

/deep/.u-modal__content__text {
  text-align: center;
}
.empty_view {
  margin-top: 300rpx;
  image {
    margin: 0 auto;
    width: 410rpx;
    height: 410rpx;
  }
  view {
    font-size: 30rpx;
    color: #d8d8d8;
    text-align: center;
  }
}
</style>